import sys
from PyQt5.QtWidgets import (
    QVBoxLayout, QToolTip, QMessageBox,
    QPushButton, QLabel, QWidget, QDialog,
    QApplication
)

from PyQt5.QtGui import QPalette, QColor, QPixmap
from PyQt5.QtCore import Qt

class MyWidget(QWidget):
    def __init__(self, parent=None):
        super(MyWidget, self).__init__(parent)
        self.initUI()

    def initUI(self):
        
        self.setGeometry(300, 300, 600, 600)#设置窗口位置和大小
        self.setWindowTitle('QWidget 实例')#设置窗口标题
        
        button = QPushButton('点击打开DIALOG', self)
        button.clicked.connect(self.showDialog)

    def showDialog(self):
        dialog = MyDialog(self)#创建一个dialog
        dialog.show()#非阻塞式显示dialog
        dialog.exec_()#阻塞式显示dialog

class MyDialog(QDialog):
    def __init__(self, parent=None):
        super(MyDialog, self).__init__(parent)
        self.initUI()

    def initUI(self):
        self.setWindowTitle('QDialog 实例')#设置窗口标题
        self.setGeometry(300, 300, 400, 300)

def main():
    app = QApplication(sys.argv)
    w = MyWidget()
    w.show()
    sys.exit(app.exec_())
    
    
if __name__ == "__main__":
    main()
